In one of my projects I have to parse HTML pages and to check if each parsed "tag candidate" is in the predefined list of tag defining strings.
The problem emerges when for some reason the parser returns "\x3C!--" as the "tag candidate", so I get false when comparing it with "<!--" from the list.
Is there any way to get true comparing those strings?
UPDATE:
To clarify my question and to explain where the error occurs I add two screenshots from DevTools panel, Google Chrome, version 104.0.5083.0 (Official Build) dev (64-bit).
We can see that the value of nodeParse.tagOpening is changed almost immediately after it has been assigned. It's quite strange.
But it's even more strange that if I open properties of nodeParse object in Local Scope, the correct (initially assigned) value is shown for tagOpening.
So it seems the browser knows that both shown values are actually equivalent, but for some reason distinguishes them. Any comments?
Within a HTML document <!-- is the opening delimiter for comments, even within <script> tags, see HTML-like Comments, so I would avoid including it as a string in your code.
Instead, you could just use the hex escape sequence in the tag-defining string in the first place. For example:
nodeParse.tagOpening = '\x3C!--';
nodeData.tagStarter = '\x3C!--';
After a deeper investigation I have revealed that "\x3C!--" == "<!--" is always true, with no extra efforts (see the screenshot below).
We should keep in mind however that string "<!--" (and any longer one) is stored as is in a variable, but is transformed into "\x3C!--" when is stored in an object's property. At least in Google Chrome.
So we should assign the object's property to a variable (like var s2 = ob.a;), if we want to get value "<!--" back for sure. It was not known to me, so I have made a mistake in my code.